package Unitest;

import java.math.BigInteger;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;

import Generators.DSAKeyPair;
import Generators.DSAKeyPairGenerator;
import Generators.DSAParameters;
import Generators.DSAParametersGenerator;
import Generators.DSAPerMessageSecretNum;
import Generators.DSAPrivateKey;
import Generators.DSAPublicKey;

public class Unit {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		DSAParametersGenerator ffcDomainParameters = new DSAParametersGenerator();
		ffcDomainParameters.initialize(2048, 256, 256);
		DSAKeyPairGenerator ffcKeyPairGeneration = new DSAKeyPairGenerator();
		DSAPrivateKey priKey = ffcKeyPairGeneration.generatePrivateKey("key1.pri");
		DSAPublicKey pubKey = ffcKeyPairGeneration.generatePublicKey("key1.pub");
		/*try {
				DSAParameters dsaParams = ffcDomainParameters.generateParameters(256, 1);
				BigInteger p = dsaParams.getP();
				BigInteger q = dsaParams.getQ();
				BigInteger g = dsaParams.getG();
				
				System.out.println("p = \n" + p.toString(16));
				System.out.println("p is prime?: " + p.isProbablePrime(256));
				System.out.println("size of p?: " + p.bitLength());
				System.out.println("q = \n" + q.toString(16));
				System.out.println("q is prime?: " + q.isProbablePrime(256));
				System.out.println("size of q?: " + q.bitLength());
				System.out.println("g = \n" + g.toString(16));
				System.out.println("Validation DSA Params: " + dsaParams.validateDSAParameters(256, 1));
				
				
				ffcKeyPairGeneration.init(dsaParams);
				DSAKeyPair dsaKeyPair = ffcKeyPairGeneration.generateKeyPair();
				if (dsaKeyPair.getStatus()  == DSAKeyPair.SUCCESS){
					DSAPrivateKey x = dsaKeyPair.getPrivateKey();
					DSAPublicKey y = dsaKeyPair.getPublicKey();
					System.out.println("private key x = \n\t" + x.getValue().toString(16));
					System.out.println("public key y = \n\t" + y.getValue().toString(16));
					x.exportToFile("key1.pri");
					y.exportToFile("key1.pub");
					//Generate per message secret number
					for (int i = 0; i < 5; i++){
						DSAPerMessageSecretNum secretNumber = ffcKeyPairGeneration.generatePerMessageSecretNumber();
						if (secretNumber.getStatus() == DSAPerMessageSecretNum.SUCCESS){
							System.out.println("k = " + secretNumber.getK().toString(16));
							System.out.println("k^-1 = " + secretNumber.getKInverse().toString(16));
						}
					}
				}

				
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
	}

}
